package com.shenhan.volatiledemo;

import java.util.concurrent.TimeUnit;

/**
 * @Author shenhan
 * @Date: 2020/6/12 22:29
 * @Description: 验证可见性
 */
public class Test {
    private static volatile int num = 0;
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (num == 0) {

            }
        }).start();

        TimeUnit.SECONDS.sleep(2L);
        num = 1;
        System.out.println(num);
    }
}
